package org.bjf.aop;

import java.util.Arrays;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Before;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 监控相关aop Created by lenovo on 2017/8/22.
 */
//@Aspect
//@Component
public class MetricsAspect {

/*
  @Autowired
  private CounterService counterService;
  @Autowired
  private GaugeService gaugeService;*/

  /**
   * 统计controller调用次数
   */

  @Before("execution(* org.bjf.modules.*..controller..*.*(..)) && @annotation(requestMapping)")
  public void countControllerInvoke(JoinPoint joinPoint, RequestMapping requestMapping) {
    System.out.println("joinPoint ========================== " + joinPoint);
    RequestMethod[] method = requestMapping.method();
    System.out.println(Arrays.toString(method));
//    counterService.increment(joinPoint.getSignature().toString());
  }

/**
 * 统计controller调用时间
 *//*

  @Around("execution(* org.bjf.modules.*..controller..*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
  public Object latencyController(ProceedingJoinPoint pjp) throws Throwable {
    long start = System.currentTimeMillis();
    Object proceed = pjp.proceed();
    long end = System.currentTimeMillis();
    gaugeService.submit(pjp.getSignature().toString(), end - start);

    return proceed;
  }
*/

}
